home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ansi / use2crts.zip / DOORS.ASM next >
Assembly Source File  |  1986-11-02  |  5KB  |  155 lines

  1. title    DOORS.ASM - Switch Color/Mono Screens On Keyboard Request
  2. ;    now assembles with masm4 (PTRs added)
  3. ;
  4. VECTORS     segment at 0h        ; 8088 / 80286 Interrupt Vector Area
  5.     org    9h*4            ; IBM PC Keyboard is Int 9H
  6. KB_INT_VECTOR    label    dword        ; Double word label
  7. ;
  8. VECTORS     ends
  9. ;
  10. ROM_BIOS_DATA    segment at 40h        ; Low Memory "BIOS" Parameters
  11. ;
  12.     org    10h            ; Location of EQUIP_FLAG
  13. EQUIP_FLAG    dw    ?        ; Contains video settings
  14.                     ; in bits 4 and 5
  15. ;
  16.     org    17h            ; Location of KB_FLAG
  17. KB_FLAG     db    ?        ; Contains Alt (bit 3) &
  18.                     ; Right Shift (bit 0) States
  19. ROM_BIOS_DATA    ends
  20. ;
  21. ; Initialization Routine
  22. ;
  23. CODE_SEG    segment
  24.     assume    cs:CODE_SEG
  25.     org    100h            ; COM program format
  26. BEGIN:    jmp    SWAP_VECTORS        ; Initialize vectors and attach to DOS
  27. ;
  28. ROM_KB_INT    dd    ?        ; Double word to save address of
  29.                     ; ROM-BIOS keyboard interrupt
  30. ; DOORS_INT intercepts the keyboard interrupt and switches
  31. ;      screens if [Alt]-[Right Shift] combination is pressed
  32. ;
  33. DOORS_INT    proc    near
  34.     assume    ds:nothing
  35.     push    ds            ; Push all affected registers
  36.     push    es
  37.     push    ax
  38.     push    bx
  39.     push    cx
  40.     push    dx
  41.     push    si
  42.     push    di
  43. ;
  44.     pushf                ; Push Flags for fake interrupt call
  45.     call    ROM_KB_INT        ; to BIOS program to read keyboard
  46. ;
  47.     assume    ds:ROM_BIOS_DATA    ; Define data segment to read
  48.     mov    ax,ROM_BIOS_DATA    ; keyboard flag & equipment flag
  49.     mov    ds,ax
  50.     mov    al,KB_FLAG        ; Get keyboard flag
  51.     and    al,09h            ; Isolate [Alt] + [Right Shift]
  52.     cmp    al,09h            ; Are they pressed?
  53.     jne    RETURN            ; No, quit
  54. ;
  55. ; [Alt] + [Right Shift] are pressed -- Continue processing
  56. ; Check on video mode - quit if not monochrome, color 80x25 or BW 80x25
  57. ;
  58.     mov    ah,15            ; Call Func 15 of Int 10h to
  59.     int    10h            ; get video state of the PC
  60.     cmp    al,7            ; Is screen monochrome?
  61.     je    SCREEN_OKAY        ; Yes, go switch screens
  62.     cmp    al,3            ; Is screen color text?
  63.     jbe    CHECK_40_OR_80        ; Yes, go check for 80 or 40 char
  64.     jmp    RETURN            ; Screen is in graphics mode, quit
  65. CHECK_40_or_80:
  66.     cmp    al,1            ; Is screen 40-character?
  67.     jbe    RETURN            ; Yes, quit
  68. ;
  69. SCREEN_OKAY:
  70. ;
  71. ; Save the current cursor position
  72. ;
  73.     mov    ah,3            ; Call Func 3 of Int 10H
  74.     mov    bh,0            ; to read cursor position
  75.     int    10h            ; (page zero for color screen)
  76. ;
  77. ; Screen switch routine - Establish calling argument (AL) for Int 10h
  78. ;
  79.     mov    bx,EQUIP_FLAG        ; Current equipment flag to BX
  80.     mov    cx,bx            ; Make a copy of it in CX
  81.     and    cx,30h            ; Extract screen information
  82.     xor    bx,cx            ; Erase current screen information in BX
  83.     or    bx,20h            ; Set BX to color 80x25
  84.     mov    al,3            ; Set AL for color 80x25 in Int 10h
  85.     cmp    cx,30h            ; Is current mono?
  86.     je    SET_MODE        ; Yes, switch to color
  87.     or    bx,30h            ; No, set BX for monochrome
  88.     mov    al,7            ; Set AL for monochrome in Int 10h
  89. SET_MODE:
  90.     mov    EQUIP_FLAG,bx        ; Write BX to equipment flag
  91.     xor    ah,ah            ; Use Func 0 of Int 10h to
  92.     int    10h            ; change screen parameters
  93. ;
  94. ; Restore Cursor
  95. ;
  96.     mov    ah,2            ; Use Func 2 of Int 10h to restore
  97.     mov    bh,0            ; cursor on new screen (position in DX)
  98.     int    10h
  99. ;
  100. ; After screens are switched, set DS and ES registers to move screen data
  101. ;
  102.     mov    ax,0b000h        ; Load ES with Mono Segment
  103.     mov    es,ax
  104.     mov    ax,0b800h        ; Load DS with Color Segment
  105.     mov    ds,ax
  106.     cmp    cx,30h            ; Did we switch from mono?
  107.     jne    COPY_THE_SCREEN     ; Yes, move data from mono to color
  108.     push    ds            ; No, swap ES and DS to move data
  109.     push    es            ; from color to mono
  110.     pop    ds
  111.     pop    es
  112. COPY_THE_SCREEN:
  113.     xor    di,di            ; Start at zero offsets
  114.     xor    si,si
  115.     mov    cx,2000         ; 2000 chars + attrs per screen
  116.     cld                ; Make sure move is 'forward'
  117. rep    movsw                ; Move Words with string instruction
  118. ;
  119. RETURN:
  120.     pop    di            ; Restore saved registers
  121.     pop    si
  122.     pop    dx
  123.     pop    cx
  124.     pop    bx
  125.     pop    ax
  126.     pop    es
  127.     pop    ds
  128.     iret                ; Return to system
  129.  
  130. DOORS_INT    endp
  131. ;
  132. ; This procedure initializes the new keyboard interupt vectors
  133. ;
  134. SWAP_VECTORS    proc    near
  135.     assume    ds:VECTORS
  136.     push    ds                ; Save Data Segment
  137.                         ; for DOS return
  138.     mov    ax,VECTORS            ; Set up the data
  139.     mov    ds,ax                ; segment for vectors
  140.     cli                    ; Disable interrupts
  141.     mov    ax,WORD PTR KB_INT_VECTOR        ; Store addresses
  142.     mov    WORD PTR ROM_KB_INT,ax            ; of BIOS program
  143.     mov    ax,WORD PTR KB_INT_VECTOR[2]
  144.     mov    WORD PTR ROM_KB_INT[2],ax
  145.     mov    WORD PTR KB_INT_VECTOR, offset DOORS_INT ; Substitute Our
  146.     mov    WORD PTR KB_INT_VECTOR[2],cs        ; Program
  147.     sti                    ; Enable interrupts
  148.     mov    dx,offset SWAP_VECTORS        ; End of new resident
  149.                         ; program
  150.     int    27h                ; Terminate resident
  151. SWAP_VECTORS    endp
  152. CODE_SEG    ends
  153.     end    BEGIN
  154. ;
  155.